<?php
/* 	These code was generated using phpCIGen v 0.1.b (21/04/2009)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com, 
	
	+ Module  		: t_salessum Controller
	+ Description	: For record controller process back-end
	+ Filename 		: C_lap_bayar.php
 	+ creator 		: 
 	+ Created on 31/May/2011 09:41:28
	
*/

//class of t_salessum
class C_lap_bayar extends CI_Controller {

	//constructor
	function C_lap_bayar(){
		parent::__construct();
		session_start();
		$this->load->model('m_lap_bayar', '', TRUE);
	}
	
	//set index
	function index(){
		$this->load->view('main/v_lap_bayar');
	}
	
	function get_list_bybayar(){
		/*if(isset($_POST["bulan"])){
			$bulan=$_POST["bulan"].'-01';
		}else{
			$bulan='';
		}*/
		if(isset($_POST["tgl_start"])){
			$tgl_start=$_POST["tgl_start"];
		}else{
			$tgl_start='';
		}
		if(isset($_POST["tgl_end"])){
			$tgl_end=$_POST["tgl_end"];
		}else{
			$tgl_end='';
		}
	
		$result=$this->m_lap_bayar->get_list_bybayar($tgl_start, $tgl_end);
		echo $result;
	}
	
	
	function print_list_bybayar(){
		//$this->load->library('html2pdf');
		
		/*if(isset($_POST["bulan"])){
			$bulan=$_POST["bulan"].'-01';
		}else{
			$bulan='';
		}*/
		if(isset($_POST["tgl_start"])){
			$tgl_start=$_POST["tgl_start"];
		}else{
			$tgl_start='';
		}
		if(isset($_POST["tgl_end"])){
			$tgl_end=$_POST["tgl_end"];
		}else{
			$tgl_end='';
		}
		
		$data["data_print"] = $this->m_lap_bayar->print_list_bybayar($tgl_start, $tgl_end);
		$data["tgl_start"] = "Tanggal ".date('d F Y', strtotime($tgl_start));
		$data["tgl_end"] = " s/d ".date('d F Y', strtotime($tgl_end));
	
		$print_view=$this->load->view("main/p_lap_bayar_bybayar.php",$data,TRUE);
		if(!file_exists("print")){
			mkdir("print");
		}
		$print_file=fopen("print/t_lap_bayar_bybayar.html","w+");
		fwrite($print_file, $print_view);
		
		/*$filename_pdf = "laporan_pembayaran_".@$_SESSION[SESSION_USERID].".pdf";
		$this->html2pdf->folder('./assets/pdfs/');
		$this->html2pdf->filename($filename_pdf);
		$this->html2pdf->paper('folio', 'landscape');
		
		$this->html2pdf->html($this->load->view("main/p_lap_bayar_bybayar_pdf.php",$data,TRUE));
		$this->html2pdf->create('save');*/
		
		echo '1';
	}
	
	function download_print_list_bybayar(){
		$file = "./assets/pdfs/laporan_pembayaran_".@$_SESSION[SESSION_USERID].".pdf";
		header("Expires: 0");
		header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
		header("Cache-Control: no-store, no-cache, must-revalidate");
		header("Cache-Control: post-check=0, pre-check=0", false);
		header("Pragma: no-cache");
		header("Content-type: application/pdf");
		// tell file size
		header('Content-length: '.filesize($file));
		// set file name
		header('Content-disposition: attachment; filename='.basename($file));
		readfile($file);
		// Exit script. So that no useless data is output-ed.
		exit;
	}
	
	// Encodes a SQL array into a JSON formated string
	function JEncode($arr){
		if (version_compare(PHP_VERSION,"5.2","<"))
		{    
			require_once("./JSON.php"); //if php<5.2 need JSON class
			$json = new Services_JSON();//instantiate new json object
			$data=$json->encode($arr);  //encode the data in json format
		} else {
			$data = json_encode($arr);  //encode the data in json format
		}
		return $data;
	}
	
	// Decode a SQL array into a JSON formated string
	function JDecode($arr){
		if (version_compare(PHP_VERSION,"5.2","<"))
		{    
			require_once("./JSON.php"); //if php<5.2 need JSON class
			$json = new Services_JSON();//instantiate new json object
			$data=$json->decode($arr);  //decode the data in json format
		} else {
			$data = json_decode($arr);  //decode the data in json format
		}
		return $data;
	}
	
	
}
?>